var t, e = require("../../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../../@babel/runtime/regenerator")), a = require("../../../../@babel/runtime/helpers/asyncToGenerator"), n = getApp();

Page({
    data: {
        active: 0,
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        point: {
            lat: "",
            lng: ""
        },
        projectList: [],
        qrCodeFlag: !1,
        posterImageUrl: ""
    },
    onLoad: (t = a(e.default.mark(function t(a) {
        var n, i = this;
        return e.default.wrap(function(t) {
            for (;;) switch (t.prev = t.next) {
              case 0:
                return t.next = 2, this.checkAlbum("scope.userLocation");

              case 2:
                n = t.sent, console.log(n), wx.getLocation({
                    type: "wgs84",
                    success: function(t) {
                        i.setData({
                            "point.lat": t.latitude,
                            "point.lng": t.longitude
                        }), i.getListData();
                    }
                });

              case 5:
              case "end":
                return t.stop();
            }
        }, t, this);
    })), function(e) {
        return t.apply(this, arguments);
    }),
    changeTags: function(t) {
        console.log(t.detail.index, this.data.active), this.data.active = 2 != t.detail.index ? t.detail.index : 9, 
        this.getListData();
    },
    onReady: function() {},
    toAppointment: function(t) {
        var e = t.currentTarget.dataset.item.has_one_order_project, a = t.currentTarget.dataset.item.has_one_store, n = a.id, i = t.currentTarget.dataset.item.has_one_worker, o = "?id=" + e.id + "&project_id=" + e.project_id + "&has_one_store=" + JSON.stringify(a);
        o += "&store_id=" + n + "&has_one_worker=" + JSON.stringify(i), wx.navigateTo({
            url: "/packageE/appointment/client/make_appointment/make_appointment" + o
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    cancelIt: function(t) {
        var e = this, a = t.currentTarget.dataset.item.id;
        wx.showModal({
            title: "您确定要取消此预约吗?",
            success: function(t) {
                t.confirm && e.cancelDate(a);
            }
        });
    },
    cancelDate: function(t) {
        var e = this, a = n.getNetAddresss("plugin.appointment.frontend.appointment-service.cancel-service");
        n._getNetWork({
            url: a,
            data: {
                id: t
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? (n.tips(a.msg), e.getListData()) : wx.showToast({
                    title: a.msg,
                    icon: "none"
                });
            }
        });
    },
    createQrc: function(t) {
        var e = this;
        wx.showLoading({
            title: "生成中",
            mask: !0
        });
        var a = t.currentTarget.dataset.item, i = n.getNetAddresss("plugin.appointment.frontend.appointment-order.qr-code-url");
        n._postNetWork({
            url: i,
            data: {
                id: a.id
            },
            success: function(t) {
                wx.hideLoading();
                var a = t.data;
                if (1 !== a.result) return e.tips(a.msg);
                e.setData({
                    qrCodeFlag: !0,
                    posterImageUrl: a.data.miQrCodeUrl
                });
            },
            fial: function(t) {
                wx.hideLoading();
            }
        });
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    setQRCodeFlag: function() {
        this.setData({
            qrCodeFlag: !this.data.qrCodeFlag
        });
    },
    gotoEvaluate: function(t) {
        var e = t.currentTarget.dataset.serverid;
        wx.navigateTo({
            url: "/packageE/appointment/client/evaluate/evaluate?service_id=" + e
        });
    },
    initData: function() {
        this.data.page = 1, this.data.isLoadMore = !0, this.data.total_page = 0;
    },
    getListData: function() {
        var t = this;
        this.initData();
        var e = n.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
        e.lng || (e.lng = "", e.lat = "");
        var a = n.getNetAddresss("plugin.appointment.frontend.appointment-service.get-list");
        n._postNetWork({
            url: a,
            data: {
                lng: e.lng.toFixed(4),
                lat: e.lat.toFixed(4),
                page: 1,
                status: this.data.active
            },
            success: function(e) {
                var a = e.data;
                if (1 !== a.result) return t.tips(a.msg);
                t.data.isLoadMore = !0, t.data.total_page = a.data.last_page, t.data.total_page || (t.data.total_page = 0), 
                t.setData({
                    projectList: a.data.data
                });
            }
        });
    },
    checkAlbum: function(t) {
        var n = this;
        return new Promise(function() {
            var i = a(e.default.mark(function a(i, o) {
                return e.default.wrap(function(e) {
                    for (;;) switch (e.prev = e.next) {
                      case 0:
                        return e.next = 2, n.getAuthSetting(t);

                      case 2:
                        e.sent ? i(!0) : wx.showModal({
                            title: "请开启授权",
                            content: "是否跳转设置页开启授权",
                            success: function(e) {
                                e.confirm ? wx.openSetting({
                                    success: function(e) {
                                        e.authSetting[t] ? i(!0) : i(!1);
                                    }
                                }) : e.cancel && i(!1);
                            },
                            fail: function() {
                                i(!1);
                            }
                        });

                      case 4:
                      case "end":
                        return e.stop();
                    }
                }, a);
            }));
            return function(t, e) {
                return i.apply(this, arguments);
            };
        }());
    },
    getAuthSetting: function(t) {
        return new Promise(function(e, a) {
            wx.getSetting({
                success: function(a) {
                    a.authSetting[t] ? e(!0) : wx.authorize({
                        scope: t,
                        success: function() {
                            e(!0);
                        },
                        fail: function() {
                            e(!1);
                        }
                    });
                },
                fail: function() {
                    e(!1);
                }
            });
        });
    },
    tips: function(t) {
        return wx.showToast({
            title: t,
            icon: "none",
            duration: 2e3
        }), !1;
    }
});